// pages/addrPage/address.js
Page({

  data: {
    userAddr: {
      userName: '',
      provinceName: '',
      cityName: '',
      countryName: '',
      detailInfo: '',
      telNumber: ''
    }
  },

  getUserAddr(){
    var that = this
    wx.chooseAddress({
      success(res) {
        console.log(res)
        that.setData({
          userName: res.userName,
          provinceName: res.provinceName,
          cityName: res.cityName,
          countryName: res.countyName,
          detailInfo: res.detailInfo,
          telNumber: res.telNumber
        });
      },
      fail(err) {
        console.log(err)
      }
    })
  },

  parentEvent:function(event){
    console.log('组件通信',event)
  },

  saveAddress(Address){
    var db = wx.cloud.database()
    db.collection('address').add({
      data:{
        city:this.data.cityName,
        country:this.data.countryName,
        detail:this.data.detailInfo,
        province:this.data.provinceName,
        telNumber:this.data.telNumber,
        userid:'',
        username:this.data.userName
      },
      success(res){
        console.log('上传成功！')
        wx.navigateTo({
          url: '../mine/mine',
        })
      },
      fail(err){
        console.log('上传失败')
      }
    })

  }
})